package com.xiao.hao.service;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiao.hao.convertor.XhSchemeListConvertor;
import com.xiao.hao.entity.XhSchemeList;
import com.xiao.hao.facade.XhSchemeListFacade;
import com.xiao.hao.mapper.XhSchemeListMapper;
import com.xiao.hao.req.XhSchemeListInsertReq;
import com.xiao.hao.req.XhSchemeListQueryPageReq;
import com.xiao.hao.req.XhSchemeListUpdateReq;
import com.xiao.hao.utils.BaseId;
import com.xiao.hao.utils.PageResult;
import com.xiao.hao.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * @Description 方案列表 服务实现层
 * @Author xiaohao
 * @Date 2025-03-05 17:23:15
 */
@Service
@Slf4j
public class XhSchemeListServiceImpl implements XhSchemeListFacade {

    @Resource
    XhSchemeListMapper mapper;


    /**
     * 功能描述: 角色新增
     *
     * @param req
     * @return com.xiao.hao.utils.Result
     * @author xiaohao
     * @date 2025-03-05 17:23:15
     */
    @Override
    public Result insert(XhSchemeListInsertReq req) {
        return Result.succeed(mapper.insert(XhSchemeListConvertor.INSTANCE.reqToEntity(req)));
    }


    /**
     * 功能描述: 角色修改
     *
     * @param req
     * @return com.xiao.hao.utils.Result
     * @author xiaohao
     * @date 2025-03-05 17:23:15
     */
    @Override
    public Result update(XhSchemeListUpdateReq req) {
        return Result.succeed(mapper.updateById(XhSchemeListConvertor.INSTANCE.reqToEntity(req)));
    }


    /**
     * 功能描述: 删除角色
     *
     * @param req
     * @return com.xiao.hao.utils.Result
     * @author xiaohao
     * @date 2025-03-05 17:23:15
     */
    @Override
    public Result delete(BaseId req) {
        return Result.succeed(mapper.deleteById(req.getId()));
    }

    /**
     * 功能描述: 角色分页查询
     *
     * @param req
     * @return com.xiao.hao.utils.PageResult
     * @author xiaohao
     * @date 2025-03-05 17:23:15
     */
    @Override
    public PageResult queryPage(XhSchemeListQueryPageReq req) {
        Page<XhSchemeList> page = mapper.selectPage(new Page(req.getNum(), req.getSize()), new LambdaQueryWrapper<XhSchemeList>()
                .eq(ObjectUtil.isNotEmpty(req.getSchemeCode()), XhSchemeList::getSchemeCode, req.getSchemeCode())
                .like(ObjectUtil.isNotEmpty(req.getTitle()), XhSchemeList::getTitle, req.getTitle())
                .orderByDesc(XhSchemeList::getCreateTime));
        return PageResult.result(page.getTotal(), XhSchemeListConvertor.INSTANCE.entityListToRespList(page.getRecords()));
    }

}



